<template>
  <div class="content-wraper">
    <div class="search-box">
      <el-form label-width="100px" :inline="true">
        <el-form-item label="合同名称">
          <el-input v-model="contractName" />
        </el-form-item>
        <el-form-item label="项目信息名称">
          <el-input v-model="projectInfoName" />
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
        <el-button type="warning" icon="el-icon-refresh" @click="reset()">重置</el-button>
        <el-button type="success" icon="el-icon-plus" @click="addGeneralContractInfo()">新增</el-button>
      </el-form>
    </div>
    <div class="detail">
      <com-table :data="dataList" :columns="columns" :total="total" @pageChange="pageChange">
        <template v-slot:name="{row}">
          <a class="com-link" @click="viewDetail(row)">{{ row.name }}</a>
        </template>
        <template v-slot:options="{row}">
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="editGeneralContractInfo(row)">编辑</el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini" @click="delGeneralContractInfo(row)">删除</el-button>
        </template>
        <template v-slot:signTime="{row: {signTime}}">
          {{ dateFormat(signTime) }}
        </template>
        <template v-slot:internation="{row: {internation}}">
          {{ getDictName(generalContractInfoInternation, internation) }}
        </template>
        <template v-slot:constructionMode="{row: {constructionMode}}">
          {{ getDictName(generalContractInfoConstructionMode, constructionMode) }}
        </template>
        <template v-slot:investmentBody="{row: {investmentBody}}">
          {{ getDictName(generalContractInfoInvestmentBody, investmentBody) }}
        </template>
        <template v-slot:projectType="{row: {projectType}}">
          {{ getDictName(generalContractInfoProjectType, projectType) }}
        </template>
        <template v-slot:startTime="{row: {startTime}}">
          {{ dateFormat(startTime) }}
        </template>
        <template v-slot:finishTime="{row: {finishTime}}">
          {{ dateFormat(finishTime) }}
        </template>
        <template v-slot:priceAdjustment="{row: {priceAdjustment}}">
          {{ getDictName(generalContractInfoPriceAdjustment, priceAdjustment) }}
        </template>
        <template v-slot:startPrepayments="{row: {startPrepayments}}">
          {{ getDictName(generalContractInfoStartPrepayments, startPrepayments) }}
        </template>
        <template v-slot:employerCtrlMaterial="{row: {employerCtrlMaterial}}">
          {{ getDictName(generalContractInfoEmployerCtrlMaterial, employerCtrlMaterial) }}
        </template>
        <template v-slot:employerSupplyMaterial="{row: {employerSupplyMaterial}}">
          {{ getDictName(generalContractInfoEmployerSupplyMaterial, employerSupplyMaterial) }}
        </template>
        <template v-slot:createTime="{row: {createTime}}">
          {{ dateFormat(createTime) }}
        </template>

      </com-table>
    </div>
    <add-general-contract-info
      :show-modal.sync="showModal"
      :opt-type="optType"
      :data="unitDetail"
      @freshList="search"
    />
  </div>
</template>

<script>
import { getGeneralContractInfoList, deleteGeneralContractInfo } from '@/api/contractManage'
import moment from 'moment'
import { getDictName } from '@/utils/comm'
import addGeneralContractInfo from '../generalContract/addGeneralContractInfo.vue'
import { generalContractInfoInternation, generalContractInfoConstructionMode, generalContractInfoInvestmentBody, generalContractInfoProjectType, generalContractInfoPriceAdjustment, generalContractInfoStartPrepayments, generalContractInfoEmployerCtrlMaterial, generalContractInfoEmployerSupplyMaterial } from '@/utils/dicData'
export default {
  name: 'GeneralContractInfo',
  components: {
    addGeneralContractInfo
  },
  data() {
    return {
      contractName: '',
      projectInfoName: '',
      getDictName,
      generalContractInfoInternation,
      generalContractInfoConstructionMode,
      generalContractInfoInvestmentBody,
      generalContractInfoProjectType,
      generalContractInfoPriceAdjustment,
      generalContractInfoStartPrepayments,
      generalContractInfoEmployerCtrlMaterial,
      generalContractInfoEmployerSupplyMaterial,

      dataList: [],
      total: 0,
      pageParams: {
        pageNum: 1,
        pageSize: 10
      },
      showModal: false,
      optType: 'add',
      unitDetail: {},
      columns: [
        /* {
          label: '合同编号',
          prop: 'contractNumber',
          width: '170'
        },*/
        {
          label: '合同名称',
          prop: 'contractName',
          width: '300'
        },
        /* {
          label: '合同主体',
          prop: 'contractBody'
        },*/
        {
          label: '合同工期',
          prop: 'contractPeriod'
        },
        {
          label: '基本合同金额',
          prop: 'basicAmount',
          width: '100'
        },
        /* {
          label: '有效合同金额',
          prop: 'validAmount',
          width: '100'
        },*/
        {
          label: '签订时间',
          prop: 'signTime',
          slot: 'signTime',
          width: '90'
        },
        /* {
          label: '是否国际',
          prop: 'internation',
          slot: 'internation'
        },
        {
          label: '省份编码',
          prop: 'provinceCode'
        },
        {
          label: '省名称',
          prop: 'provinceName'
        },
        {
          label: '国家',
          prop: 'nation'
        },*/
        {
          label: '承建模式',
          prop: 'constructionMode',
          slot: 'constructionMode',
          width: '90'
        },
        /* {
          label: '投资主体',
          prop: 'investmentBody',
          slot: 'investmentBody'
        },*/
        {
          label: '项目类型',
          prop: 'projectType',
          slot: 'projectType',
          width: '90'
        },
        /* {
          label: '待建业主',
          prop: 'builtOwner'
        },*/
        {
          label: '甲方名称',
          prop: 'employerName',
          width: '150'
        },
        /* {
          label: '甲方联系人',
          prop: 'employerContactPerson',
          width: '100'
        },
        {
          label: '甲方联系电话',
          prop: 'employerContactPhone',
          width: '100'
        },
        {
          label: '甲方法人',
          prop: 'employerLegalPerson'
        },*/
        {
          label: '乙方名称',
          prop: 'employeeName',
          width: '150'
        },
        /* {
          label: '乙方联系人',
          prop: 'employeeContactPerson',
          width: '100'
        },
        {
          label: '乙方联系电话',
          prop: 'employeeContactPhone',
          width: '100'
        },
        {
          label: '乙方法人',
          prop: 'employeeLegalPerson'
        },
        {
          label: '开工时间',
          prop: 'startTime',
          slot: 'startTime',
          width: '90'
        },
        {
          label: '完工时间',
          prop: 'finishTime',
          slot: 'finishTime',
          width: '90'
        },
        {
          label: '价格调整',
          prop: 'priceAdjustment',
          slot: 'priceAdjustment'
        },
        {
          label: '开工预付款',
          prop: 'startPrepayments',
          slot: 'startPrepayments',
          width: '100'
        },
        {
          label: '甲控材',
          prop: 'employerCtrlMaterial',
          slot: 'employerCtrlMaterial'
        },
        {
          label: '甲供材',
          prop: 'employerSupplyMaterial',
          slot: 'employerSupplyMaterial'
        },
        {
          label: '预付款金额',
          prop: 'prepaymentsAmount',
          width: '100'
        },
        {
          label: '质保期信息',
          prop: 'warrantyInfo',
          width: '100'
        },
        {
          label: '质保金比例',
          prop: 'warrantyRatio',
          width: '100'
        },
        {
          label: '描述',
          prop: 'description'
        },
        {
          label: '摘要',
          prop: 'summary'
        },*/
        {
          label: '项目信息名称',
          prop: 'projectInfoName',
          width: '230'
        },
        /* {
          label: '项目信息地址',
          prop: 'projectInfoAddress',
          width: '100'
        },
        {
          label: '项目信息概况',
          prop: 'projectInfoSummary',
          width: '100'
        },
        {
          label: '备注',
          prop: 'remark'
        },*/
        {
          label: '编制人',
          prop: 'founderName'
        },
        {
          label: '编制时间',
          prop: 'createTime',
          slot: 'createTime',
          width: '90'
        },

        {
          fixed: 'right',
          label: '操作',
          width: '180',
          prop: 'options',
          slot: 'options'
        }
      ]
    }
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    dateFormat(data) {
      if (data) {
        return moment(data).format('YYYY-MM-DD')
      } else {
        return ''
      }
    },
    pageChange(data) {
      this.pageParams = data
      this.getDataList()
    },
    getDataList() {
      const params = {
        ...this.pageParams,
        contractName: this.contractName,
        projectInfoName: this.projectInfoName
      }
      getGeneralContractInfoList(params).then(res => {
        const { data, total } = res.data || {}
        if (data) {
          this.dataList = data
          this.total = total - 0
        }
      })
    },
    addGeneralContractInfo() {
      this.optType = 'add'
      this.showModal = true
    },
    editGeneralContractInfo(data) {
      this.optType = 'edit'
      this.unitDetail = data
      this.showModal = true
    },
    viewDetail(data) {
      this.optType = 'detail'
      this.unitDetail = data
      this.showAddFileModal = true
    },
    delGeneralContractInfo(data) {
      this.$confirm('确定要删除该总承包合同吗, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const { id } = data
        deleteGeneralContractInfo({
          generalContractInfoId: id
        }).then(res => {
          const { code, msg } = res
          if (code === '0001') {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getDataList()
          } else {
            this.$message({
              type: 'error',
              message: msg || '删除失败!'
            })
          }
        })
      }).catch(() => {
      })
    },
    search() {
      this.pageParams.pageNum = 1
      this.getDataList()
    },
    reset() {
      this.contractName = ''
      this.projectInfoName = ''
    }

  }
}
</script>

<style lang="scss" scoped>
.search-box {
  height: 50px;
}
.detail{
  height: calc(100% - 50px);
}
</style>
